<template>
  <el-card>
    <el-form :inline="true">
      <el-form-item label="一级分类">
        <el-select
                   :disabled="scene === 1"
                   v-model="categoryStore.c1Id"
                   @change="getCategory2"
                   style="width: 200px;">
          <el-option
                     v-for="c1 in categoryStore.c1Arr"
                     :key="c1.id"
                     :label="c1.name"
                     :value="c1.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select
                   :disabled="scene === 1"
                   v-model="categoryStore.c2Id"
                   @change="getCategory3"
                   style="width: 200px;">
          <el-option
                     v-for="c2 in categoryStore.c2Arr"
                     :key="c2.id"
                     :label="c2.name"
                     :value="c2.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select
                   :disabled="scene === 1"
                   v-model="categoryStore.c3Id"
                   style="width: 200px;">
          <el-option
                     v-for="c3 in categoryStore.c3Arr"
                     :key="c3.id"
                     :label="c3.name"
                     :value="c3.id"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script setup lang="ts">
import { onMounted } from "vue";
import useCategoryStore from "@/store/modules/category";
// 获取分类相关二级仓库
const categoryStore = useCategoryStore();
onMounted(() => {
  // 通知分类仓库发请求获取一级分类的数据
  categoryStore.getC1();
});
// 一级分类值改变触发
const getCategory2 = () => {
  // 清空二级和三级分类数据
  categoryStore.c2Id = "";
  categoryStore.c3Id = "";
  categoryStore.c2Arr = [];
  categoryStore.c3Arr = [];
  // 获取二级分类数据
  categoryStore.getC2(categoryStore.c1Id);
};
// 二级分类值改变触发
const getCategory3 = () => {
  // 清空三级分类数据
  categoryStore.c3Id = "";
  categoryStore.c3Arr = [];
  // 获取三级分类数据
  categoryStore.getC3(categoryStore.c2Id);
};
// 接受父组件传递的值
defineProps(["scene"]);
</script>

<style scoped></style>
